package com.ruoyi.crm.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.AuditStatus;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.crm.domain.CrmContract;
import com.ruoyi.crm.domain.CrmOrder;
import com.ruoyi.crm.domain.CrmOrderCollectPayMoney;
import com.ruoyi.crm.domain.CrmOrderRegister;
import com.ruoyi.crm.domain.dto.CrmProjectDTO;
import com.ruoyi.crm.domain.dto.CrmStatisticsSearchDTO;
import com.ruoyi.crm.mapper.CrmDataStatisticsMapper;
import com.ruoyi.crm.service.ICrmContractService;
import com.ruoyi.crm.service.ICrmDataStatisticsService;
import com.ruoyi.crm.service.ICrmOrderRegisterService;
import com.ruoyi.crm.service.ICrmOrderService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author YanWenliang
 * @date 2024/12/20 10:06
 * @desciption: 数据统计
 */
@RestController
@RequestMapping("/crm/statistics")
public class CrmDataStatisticsController extends BaseController {

    @Autowired
    private ICrmDataStatisticsService crmDataStatisticsService;

    /**
     * 统计商机数量、待续费数据
     * @return
     */
    @PostMapping("statisticsProjectNumberAndTodoAndRenewed")
    public AjaxResult statisticsProjectNumberAndTodoAndRenewed(){
        return AjaxResult.success(crmDataStatisticsService.statisticsProjectNumberAndTodoAndRenewed());
    }

    /**
     * 统计业绩数据
     * @param crmStatisticsSearchDTO
     * @return
     */
    @PostMapping("statisticsPerformance")
    public AjaxResult statisticsPerformance(@RequestBody CrmStatisticsSearchDTO crmStatisticsSearchDTO){
        // 统计业绩数据
        return  AjaxResult.success(crmDataStatisticsService.statisticsPerformance(crmStatisticsSearchDTO));
    }

    /**
     * 统计实际支出数据
     * @param crmStatisticsSearchDTO
     * @return
     */
    @PostMapping("statisticsActualSpending")
    public AjaxResult statisticsActualSpending(@RequestBody CrmStatisticsSearchDTO crmStatisticsSearchDTO){
        // 统计实际支出数据
        return  AjaxResult.success(crmDataStatisticsService.statisticsActualSpending(crmStatisticsSearchDTO));
    }

    /**
     * 统计待办数据数量
     * @param crmStatisticsSearchDTO
     * @return
     */
    @PostMapping("statisticsToDo")
    public AjaxResult statisticsToDo(@RequestBody CrmStatisticsSearchDTO crmStatisticsSearchDTO){
        return AjaxResult.success(crmDataStatisticsService.statisticsToDo(crmStatisticsSearchDTO));
    }

    /**
     * 销售额排行
     * @param crmStatisticsSearchDTO
     * @return
     */
    @PostMapping("statisticsSales")
    public AjaxResult statisticsSales(@RequestBody CrmStatisticsSearchDTO crmStatisticsSearchDTO){
        return AjaxResult.success(crmDataStatisticsService.statisticsSales(crmStatisticsSearchDTO));
    }

    /**
     * 成交次数客户排行
     * @param crmStatisticsSearchDTO
     * @return
     */
    @PostMapping("statisticsTransactionsCount")
    public AjaxResult statisticsTransactionsCount(@RequestBody CrmStatisticsSearchDTO crmStatisticsSearchDTO){
        return AjaxResult.success(crmDataStatisticsService.statisticsTransactionsCount(crmStatisticsSearchDTO));
    }



    /**
     * 统计商机数量、待续费列表数据
     * @return
     */
    @GetMapping("getOrderAndIsRenewalList")
    public TableDataInfo getOrderAndIsRenewalList( CrmStatisticsSearchDTO crmStatisticsSearchDTO){
        startPage();
        List<CrmOrder> orderAndIsRenewalList = crmDataStatisticsService.getOrderAndIsRenewalList(crmStatisticsSearchDTO);
        return getDataTable(orderAndIsRenewalList);
    }

    /**
     * 统计合同列表
     * @param crmStatisticsSearchDTO
     * @return
     */
    @GetMapping("getContractMoneySumList")
    public TableDataInfo getContractMoneySumList( CrmStatisticsSearchDTO crmStatisticsSearchDTO){
        startPage();
        List<CrmProjectDTO> contractMoneySumList = crmDataStatisticsService.getContractMoneySumList(crmStatisticsSearchDTO);
        return getDataTable(contractMoneySumList);
    }

    /**
     * 统计90，60，30 数据列表
     * @param crmStatisticsSearchDTO
     * @return
     */
    @GetMapping("getPerformanceList")
    public TableDataInfo getPerformanceList( CrmStatisticsSearchDTO crmStatisticsSearchDTO){
        startPage();
        List<CrmOrder> performanceList = crmDataStatisticsService.getPerformanceList(crmStatisticsSearchDTO);
        return getDataTable(performanceList);
    }

    /**
     * 付款数据
     * @param crmStatisticsSearchDTO
     * @return
     */
    @GetMapping("getPayAmtList")
    public TableDataInfo getPayAmtList( CrmStatisticsSearchDTO crmStatisticsSearchDTO){
        startPage();
        List<CrmOrderCollectPayMoney> performanceList = crmDataStatisticsService.getPayAmtList(crmStatisticsSearchDTO);
        return getDataTable(performanceList);
    }


    /**
     * 收款数据
     * @param crmStatisticsSearchDTO
     * @return
     */
    @GetMapping("getCollectionAmtList")
    public TableDataInfo getCollectionAmtList( CrmStatisticsSearchDTO crmStatisticsSearchDTO){
        startPage();
        List<CrmOrderCollectPayMoney> performanceList = crmDataStatisticsService.getCollectionAmtList(crmStatisticsSearchDTO);
        return getDataTable(performanceList);
    }
}
